package com.cityfood.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cityfood.mapper.CfCardTypeMapper;
import com.cityfood.pojo.CfCardType;
import com.cityfood.pojo.CfCardTypeExample;
import com.cityfood.service.CardTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class CardTypeServiceImpl implements CardTypeService {

	@Autowired
	private CfCardTypeMapper typeMapper;

	@Override
	public PageInfo<CfCardType> selectCardType(Integer pageNum, Integer pageSize) {
		
		//设置分页的页数和行数
		PageHelper.startPage(pageNum, 20);
		
		CfCardTypeExample example = new CfCardTypeExample();
		List<CfCardType> list = typeMapper.selectByExample(example );
		if (list.size()>0) {
			//5.获取分页信息
			PageInfo<CfCardType> info = new PageInfo<>(list);
			return info;
		}
		return null;
	}

	@Override
	public int insertCardType(CfCardType cardType) {
		int i = typeMapper.insertSelective(cardType);
		return i;
	}

	@Override
	public int updateCardType(CfCardType cardType) {
		int i = typeMapper.updateByPrimaryKeySelective(cardType);
		return i;
	}

	@Override
	public int deleteCardType(Integer typeId) {
		int i = typeMapper.deleteByPrimaryKey(typeId);
		return i;
	}

	@Override
	public CfCardType selectCardTypeById(Integer id) {
		CfCardType cardType = typeMapper.selectByPrimaryKey(id);
		return cardType;
	}
	
	@Override
	public List<CfCardType> selectAllCardType(){
		CfCardTypeExample example = new CfCardTypeExample();
		return typeMapper.selectByExample(example);
	}
	
}
